package gmall;

import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.api.response.AlipayTradePagePayResponse;

public class AlipayDemo {


    public static void main(String[] args) throws Exception {
        //1:支付宝的客户端
        AlipayClient alipayClient =  //沙箱版
                new DefaultAlipayClient(
                        "https://openapi.alipaydev.com/gateway.do",
                        "2021000119611373",
                        "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCLxIf0UmNmbRpZyUdz5UgjY4SZWC3MTKm+1s/bzJPwsPIOXLKUufZ5cCA5AjlWYbxymJRD/I6orLvPkjdERsu2axHbV6GU8y0uHwP0NMaux7z76YadHMCG798fGRUqqmyyvEB8dartl4Ydli7TZ+6iL2dAIvhz47eKvzWm1O78ysY4/idiF9XYX2F6RjQ0XMNElCsBt5HinA/WpvTS3coY90grx/zpHN/kc/dTV04BFf/te6xwubjN3lnwpz/4uMGIZtJv7nDiRdiTW7PG5TeC7PNuchd+GYxcdqEFGtD975M7VZOC1+OAbO2HiXxmWc10h67ap8cKNrgoifMmjE1NAgMBAAECggEBAIt8duZJdvQYvGyQ6ONsFmNjBUl4bDRw6hMQFN9aOubB4MCemIa/VJD7at0aMBjab5S6W3XCTqldwg208b0NHm8OSgLqYNLjIdrejzafmQ2DP0L1WyffMvE34SgLA0nSTarPH1hWomB9kRZj9JV9KvXncxbaD7SwtVMd4rB934ieY7mGXduhJbHusp2uZGe/K+dDXcgzwa/AorYP1UqwclqkFrasS/eQyLYOoAkhX+2QwlZ9zeRxJiM1uGxIT/LA9stG7Huq53PWLx/CiBneK11cD+WWJzQR7RJGnyWOPWlmSTF9aIkkYj3RDNThyHTS8lhgshCWF9cQEWRYV3i32q0CgYEA3OswYEci90NDloeUf1vyHa+egQbOsl/NMPQ66Mv4PJEC0NcLV5I+EB5g1LaiAvdMnU8QzD2F0VMiIcxbSFGHuoAawPLDnXVePyOyzMLyGYE8MPevtrlYYkEAYSZhm9IKpX5okHfdLCaExfMO+BNmRPrI3dQnj+BNcq4qjNq7Gd8CgYEAofZh84uzjtY4uDO4+Xpl9Yhv/IeVUd3RHpJQgpUKjWvPnx9WT1T/GgU6HXdRwAq4LOiuvIq1pEn+a2KEEiGsytE+LZ74vKyFhEjkaJrdEn5FFRtmlAC/vDwJOaheAYjUyeLNywrFsNVfCsTNoYRIX7iQ7BkSj6AFzZ+guukOVlMCgYBzyXzgaUhlSkbpZYQqQFmkv4AW5id9jAKyrr8VdppTvDk6lgsmycpnjlR4CITfgxgPtvn54iD59lWEW2RYggreb/gVuudV5scP1rkG4wIa5gZTL+5Tmc8+KA133bL5BVx5IsjRN1Gfq0yZp2voD9rhOoP+6AwYN5rACZLZombABwKBgF2pqoO5qqFT6YE9CB/eVNBlkr2rewLZEHJpkv2xS2T1kCApczR1pwFZPH6F3lT83f26ojKO1PSpheR8GHyT1OWFlDu1z4rtClmx/cUwqeBj/XdzXSMCO9+TqJIbeCHTC5uk+fYNyL225zvHDFP3uBMDHWwsI7vDgxei1MTCunPZAoGBAIH/S/a7pz88HcLn0QJzzaHi74Lek47JPhWjTIltCXlfUqujm1G/BJ26DZU/SHxVuZujkbsU78ctxZTqKktx3ru/IfhHYAICnbXil0qNCkLUvz45MGBc8cIB8vFJijBCD5iQgu1Hnd2DdquCjk/dNa8jBH8X2ugZWRulgNFpLZXN",
                        "json",
                        "UTF-8",
                        "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApWGld6DYf7a8pUGCPC0HqvZSDGNum/1OvlJA0PdQRKEaau7DDcpyysY68MAKErV/B/r31kOZUF0BafIbPtV3Eb9W1jaE2SHXQDPpp2U22RAtKY4BV5xQTSX0pOnq6RCR2OrnsizcLNg0DyNeF6nrKt2Qq31dZy3jYq91telKbwvNRhie52O45ZZhNKLCj3t6yvkW43hfBbew0mbEfRil5LoZLpCH8M2AQIvVF1x3waCyHPSgx098dgh8YvrA7LMxAEBu8ZPyTQvzzsTLvMQxRvABAjuMCsz86sfMvGAvuiJfbb0j9n2zjnmT5828k/BeujHhfcu0mYRHJJvvtXWYQwIDAQAB",
                        "RSA2");
        //统一收单下单并支付页面接口
        // alipay.trade.page.pay
        AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
        request.setNotifyUrl("");
        request.setReturnUrl("");
        JSONObject bizContent = new JSONObject();
        bizContent.put("out_trade_no", "20210817010101004");//商户订单号
        bizContent.put("total_amount", 0.01);
        bizContent.put("subject", "测试商品123");
        bizContent.put("product_code", "FAST_INSTANT_TRADE_PAY");
        //bizContent.put("time_expire", "2022-08-01 22:00:00");
        //bizContent.put("qr_pay_mode", "3");

        //// 商品明细信息，按需传入
        //JSONArray goodsDetail = new JSONArray();
        //JSONObject goods1 = new JSONObject();
        //goods1.put("goods_id", "goodsNo1");
        //goods1.put("goods_name", "子商品1");
        //goods1.put("quantity", 1);
        //goods1.put("price", 0.01);
        //goodsDetail.add(goods1);
        //bizContent.put("goods_detail", goodsDetail);

        //// 扩展信息，按需传入
        //JSONObject extendParams = new JSONObject();
        //extendParams.put("sys_service_provider_id", "2088511833207846");
        //bizContent.put("extend_params", extendParams);

        request.setBizContent(bizContent.toString());
        AlipayTradePagePayResponse response = alipayClient.pageExecute(request);
        if(response.isSuccess()){
            System.out.println("调用成功");
            System.out.println(response.getBody());//返回页面
        } else {
            System.out.println("调用失败");
        }


    }
}
